package ltd.sshine.networkclient.handler;

import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;
import io.netty.handler.codec.http.FullHttpRequest;
import lombok.extern.slf4j.Slf4j;
import ltd.sshine.networkclient.service.ProxyService;
@Slf4j
public class HttpProxyChannelHandler extends ChannelInboundHandlerAdapter {


    private final String host;
    private final int port;
    public HttpProxyChannelHandler(String host, int port, ProxyService proxyService) {
        this.host = host;
        this.port = port;
        this.proxyService = proxyService;
    }

    private final ProxyService proxyService ;

    @Override
    public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
        log.debug("收到消息");
        FullHttpRequest fullHttpRequest = (FullHttpRequest) msg;
        proxyService.proxy(ctx, fullHttpRequest, host, port);
    }
}
